package org.example.warehouse.listener;

import org.example.core.to.mq.OrderTo;
import org.example.core.to.mq.StockDetailTo;
import org.example.warehouse.service.WareSkuService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 小杰_cc
 * @version 1.0
 */
@Service
@RabbitListener(queues = "stock.release.stock.queue")
public class StockLockedListener {

    @Autowired
    private WareSkuService wareSkuService;

    // 自动解锁
    @RabbitHandler
    public void handleStockedLocked(StockDetailTo to){
        // auto模式，出现异常自动重试
        System.out.println("自动解锁库存");
        wareSkuService.autoUnLockedStock(to);
    }

    // 主动解锁
    @RabbitHandler
    public void handleOrderClose(OrderTo to){
        System.out.println("主动解锁库存");
        wareSkuService.activeUnLockedStock(to);
    }
}
